Expand description

A Rust crate that convert bytes into human-readable values.

It can return either KB/MB/GB/TB or KiB/MiB/GiB/TiB via the bibytes feature, which enables the IEC prefix.

(1 KB = 1024 B, 1 KiB = 1024 B, the only thing that changes is the suffix)

It supports from 0 bytes to several yottabytes (I cannot tell how many because I have to use u128s to fit a single YB)

For more info, check the README.md

Example

use human_bytes::human_bytes;

assert_eq!(human_bytes(563_200_u32), "550 KB".to_string());
// or
assert_eq!(human_bytes(563_200_u64 as f64), "550 KB".to_string());
// ________________________________/
// |
// | Needed only when you're using `u64` values,
// | because `f64` doesn't implement `std::convert::From<u64>`

// With the `bibytes` feature enabled:
assert_eq!(human_bytes(563_200_u32), "550 KiB".to_string());

Functions

Converts bytes to human-readable values